package com.crack.nga2.volley;

import android.support.annotation.NonNull;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 上传文件包装类
 * Created by Administrator on 2016/1/7.
 */
public class UploadAttach {
    /**
     * 文件类型
     */
    String type;
    /**
     * 文件名
     */
    String fileName;
    /**
     * 文件对象
     */
    File file;
    /**
     * 附加参数
     */
    Map<String, String> params;
    /**
     * 编号
     */
    int no;
    private String dscp ;
    private String waterMark;
    private int fid;
    private String auth;

    public UploadAttach(File file, String type, String fileName, int no, int fid, String auth) {
        this(file, type, fileName, null, null, no, fid, auth);
    }

    public UploadAttach(File file, String type, String fileName, String dscp, int no, int fid, String auth) {
        this(file, type, fileName, dscp, null, no, fid, auth);
    }

    public UploadAttach(@NonNull File file, @NonNull String type, @NonNull String fileName, String dscp, String waterMark, int no, int fid, @NonNull String auth) {
        this.file = file;
        this.no = no;
        this.waterMark = waterMark;
        this.type = type;
        this.fid = fid;
        this.auth = auth;
        try {
            if(dscp==null)dscp="";
            this.dscp = URLEncoder.encode(dscp, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        params = new HashMap<>();
        params.put("lite", "js");
        params.put("func", "upload");
        params.put("v2", String.valueOf(1));
        params.put("fid", String.valueOf(fid));
        params.put("auth", auth);
        try {
            params.put("attachment_file" + no + "_url_utf8_name", URLEncoder.encode(fileName, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        params.put("attachment_file" + no + "dscp", dscp);
        if (waterMark != null) {
            params.put("attachment_file" + no + "_watermark", waterMark);
        }
    }

    public String getDscp() {
        return dscp;
    }

    public void setDscp(String dscp) {
        this.dscp = dscp;
    }

    public String getWaterMark() {
        return waterMark;
    }

    public void setWaterMark(String waterMark) {
        this.waterMark = waterMark;
    }

    public int getFid() {
        return fid;
    }

    public void setFid(int fid) {
        this.fid = fid;
    }

    public String getAuth() {
        return auth;
    }

    public void setAuth(String auth) {
        this.auth = auth;
    }
}
